import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: JSON.parse(window.localStorage.getItem('user')),
    userInfo:{},
    cachePages:['Layout']
  },
  mutations: {
    setUser(state,data){
      state.user=data
      window.localStorage.setItem('user',JSON.stringify(data))
    },
    addCachePage(state,pageName){
      if(!state.cachePages.includes(pageName)){
        state.cachePages.push(pageName)
      }
    },
    removeCachePage(state,pageName){
      const index=state.cachePages.indexOf(pageName)
      if(state.cachePages.includes(pageName)){
        if(index!==-1){
          state.cachePages.splice(index,1)
        }
      }
    }
  },
  actions: {
  }
})
